package org.eiahe.hr.performance.controller;

import lombok.RequiredArgsConstructor;
import org.ehe.common.core.BaseController;
import org.eiahe.hr.performance.domain.PerformanceLevel;
import org.eiahe.hr.performance.service.IPerformanceLevelService;
import org.ehe.common.core.domain.R;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.mybatis.core.page.PageQuery;
import org.ehe.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.dev33.satoken.annotation.SaCheckPermission;

import java.util.List;

/**
 * 绩效等级Controller
 *
 * @author zhangnn
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/performance/level")
public class PerformanceLevelController extends BaseController {

    private final IPerformanceLevelService performanceLevelService;

    /**
     * 查询绩效等级列表
     */
    @SaCheckPermission("performance:level:list")
    @GetMapping("/list")
    public TableDataInfo<PerformanceLevel> list(PerformanceLevel level, PageQuery pageQuery) {
        return performanceLevelService.queryPageList(level, pageQuery);
    }

    /**
     * 获取绩效等级详细信息
     */
    @SaCheckPermission("performance:level:query")
    @GetMapping(value = "/{levelId}")
    public R<PerformanceLevel> getInfo(@PathVariable("levelId") Long levelId) {
        return R.ok(performanceLevelService.queryById(levelId));
    }

    /**
     * 新增绩效等级
     */
    @SaCheckPermission("performance:level:add")
    @Log(title = "绩效等级", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody PerformanceLevel level) {
        return toAjax(performanceLevelService.insertByBo(level));
    }

    /**
     * 修改绩效等级
     */
    @SaCheckPermission("performance:level:edit")
    @Log(title = "绩效等级", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody PerformanceLevel level) {
        return toAjax(performanceLevelService.updateByBo(level));
    }

    /**
     * 删除绩效等级
     */
    @SaCheckPermission("performance:level:remove")
    @Log(title = "绩效等级", businessType = BusinessType.DELETE)
    @DeleteMapping("/{levelIds}")
    public R<Void> remove(@PathVariable Long[] levelIds) {
        return toAjax(performanceLevelService.deleteWithValidByIds(List.of(levelIds), true));
    }
}